<template>
  <div>
    <detention-search>
      <el-row>
        <el-button type="warning" size="small" icon="el-icon-upload2">上报</el-button>
        <el-button
          type="warning"
          size="small"
          icon="el-icon-upload2"
          @click="getRepMonthControllerAudit"
        >审核</el-button>
        <el-button type="info" size="small" icon="el-icon-info">汇总生成</el-button>
        <el-button type="primary" size="small" icon="el-icon-refresh">刷新</el-button>
        <el-button size="small" icon="el-icon-printer">打印</el-button>
      </el-row>
    </detention-search>
    <detention-list :data-list.sync="dataList"/>
    <div class="pagination">
      <div>总数：{{total}}</div>
      <div>
        <el-pagination
          background
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import detentionSearch from './search';
import detentionList from './list';

export default {
  name: 'detention',
  components: {
    detentionSearch,
    detentionList
  },
  data() {
    return {
      dataList: [],
      total: 0,
      form: {
        depCode: '330304000000',
        repType: '31',
        beginDate: '2018-12-01 00:00:00',
        endDate: '2018-12-31 00:00:00',
        currentPage: 1,
        pageSize: 10
      }
    };
  },
  methods: {
    async getRepMonthControllerList() {
      const res = await this.$services.post({
        type: 'REPORT',
        url: 'getRepMonthControllerList',
        params: this.form
      });
      res.bean.list.forEach(rep => {
        rep.checked = false;
      });
      this.dataList = res.bean.list;
      this.total = res.bean.total;
    },
    handleCurrentChange(val) {
      this.form.currentPage = val;
      this.getRepMonthControllerList();
    },
    async getRepMonthControllerAudit() {
      let ids = [];
      this.dataList.forEach(data => {
        if (data.checked) {
          ids.push({
            value: data.id
          });
        }
      });
      const res = await this.$services.post({
        type: 'REPORT',
        url: 'getRepMonthControllerAudit',
        params: {
          ids: JSON.stringify(ids)
        }
      });
      if (res.status) {
        this.$message({
          message: '审核成功',
          type: 'success'
        });
        this.getRepMonthControllerList();
      }
    }
  },
  created() {
    this.getRepMonthControllerList();
  }
};
</script>

<style lang="scss">
.pagination {
  text-align: right;
  margin: 5px 0;

  > div {
    display: inline-block;
    vertical-align: middle;
  }

  .el-pagination {
    padding: 2px 0;
  }
}
</style>
